<template>
  <el-config-provider :locale="locale">
    <router-view />
  </el-config-provider>
</template>

<script lang="ts">
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
import { useGlobalStore } from '@/stores/global'
import { ElMessage } from 'element-plus'

export default defineComponent({
  setup() {
    const globalStore = useGlobalStore()
    const route = useRoute()
    const error = computed(() => globalStore.error)

    watch(
      () => error.value.status,
      newValue => {
        if (newValue && !route.meta.disableError) {
          ElMessage.error({ message: error.value.message || '未知错误', duration: 2000 })
        }
      }
    )
    return {
      locale: zhCn
    }
  }
})
</script>

<style>
#app {
  color: var(--el-text-color-primary);
}
</style>
